package com.mostonsoft.contact.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mostonsoft.contact.form.Contact;

@Repository
public class ContactDAOImpl implements ContactDAO{
	
	@Autowired
	SessionFactory sessionFactory;

	public void addContact(Contact contact) {
		sessionFactory.getCurrentSession().save(contact);
		
	}

	public List<Contact> listContact() {
		
		return sessionFactory.getCurrentSession().createQuery("from contact").list();
	}

	public void removeContact(Integer id) {
		Contact contact=(Contact)sessionFactory.getCurrentSession().load(Contact.class, id);
		if(null!=contact){
			sessionFactory.getCurrentSession().delete(contact);
		}
	}

}
